package com.neuedu.his.controller;


import com.neuedu.his.entity.FeeItem;
import com.neuedu.his.entity.Register;
import com.neuedu.his.entity.Role;
import com.neuedu.his.entity.RoleMenu;
import com.neuedu.his.framework.PageInfo;
import com.neuedu.his.framework.annotation.MethodAlias;
import com.neuedu.his.framework.servlet.BaseServlet;
import com.neuedu.his.service.RegisterService;
import com.neuedu.his.service.RoleService;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;
import java.util.List;

/**
 * 项目：      his
 * 类名:       RegisterController
 * 创建时间：  2020/12/22  11:05
 * 描述 :
 * 作者 :     张金山
 * QQ :     314649444
 * Site:      https://jshand.gitee.io
 */
@WebServlet(name = "RegisterController", urlPatterns = "/register")
public class RegisterController extends BaseServlet {

    private RegisterService registerService = new RegisterService();


    /**
     * 退号
     * @param request
     * @param response
     * @throws IOException
     */
    public void unregist(HttpServletRequest request, HttpServletResponse response) throws IOException {

        boolean success = registerService.unregist(request);
        //将结果以json格式返回
        this.success(response, success);
    }



    @MethodAlias("query")
    public void list(HttpServletRequest request, HttpServletResponse response) throws IOException {

        PageInfo pageInfo = registerService.queryListByPage(request);
        //将结果以json格式返回
        this.success(response, pageInfo);
    }


    public void listAll(HttpServletRequest request, HttpServletResponse response) throws IOException {

        List<Register> registerList = registerService.queryList(request);
        //将结果以json格式返回
        this.success(response, registerList);
    }

    /**
     * 根据病历号 查询可以退号的 患者列表
     * @param request
     * @param response
     * @throws IOException
     */
    public void queryRegistListById(HttpServletRequest request, HttpServletResponse response) throws IOException {

        List<Register> registerList = registerService.queryRegistListById(request);
        //将结果以json格式返回
        this.success(response, registerList);
    }

    //http://127.0.0.1:8080/his/user?type=add
    public void save(HttpServletRequest request, HttpServletResponse response) throws ParseException, NoSuchFieldException, IllegalAccessException, InstantiationException, IOException {

        Register register = parseParameter(request, Register.class);

        boolean success = false;
        if (register.getId() != null) { //修改
            success = registerService.update(register);
        } else { //添加
            success = registerService.save(register);
        }

        super.success(response, success);
    }

    public void toEdit(HttpServletRequest request, HttpServletResponse response) throws ParseException, NoSuchFieldException, IllegalAccessException, InstantiationException, IOException {

        String id = request.getParameter("id"); //   "" NumberFormatException

        Register register = registerService.queryById(Integer.parseInt(id));

        super.success(response, register);
    }


    public void del(HttpServletRequest request, HttpServletResponse response) throws ParseException, NoSuchFieldException, IllegalAccessException, InstantiationException, IOException {

        String id = request.getParameter("id");

        boolean success = registerService.deleteById(Integer.parseInt(id));

        super.success(response, success);
    }


    /**
     * 根据 病历号查询所有检查、检验项目
     * http://127.0.0.1:8080/his/register?type=queryFeeItemList&registerId=2
     */

    public void queryFeeItemList(HttpServletRequest request, HttpServletResponse response) throws ParseException, NoSuchFieldException, IllegalAccessException, InstantiationException, IOException {

        List<FeeItem> list =  registerService.queryFeeItemList(request);

        super.success(response, list);
    }


    /**
     * 费用送收付，生成挂账科目
     * 修改状态，---》 待检查
     *  checckApplyIds
     *  inspectApplyIds
     *   update check_apply set status = 2 where id in(  ?/.....)
     *   update inspect_apply set status = 2 where id in(  ?/.....)
     *
     *   http://127.0.0.1:8080/his/register?type=fee&checckApplyIds=1,2&inspectApplyIds=2
     */

    public void fee(HttpServletRequest request, HttpServletResponse response) throws IOException {

        boolean success = registerService.fee(request);

        super.success(response,success);


    }





}